<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" >
      <!--   rules规则列表   -->
      <el-table-column type="expand" style="width: 100%">
        <template  #default="{row}">
          <el-table  :data="row.rules" style="width: 100%">
            <el-table-column
              prop="title"
              label="规则名称">
            </el-table-column>
            <el-table-column
              prop="details"
              label="规则详情">
              <template #default="{row}">
                <div v-for="(t,i) in row.details" :key="i">
                  {{row.details[i]}}
                </div>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
<!--        <el-radio :label="2">市场规则</el-radio>
            <el-radio :label="1">飞机规则</el-radio>
            <el-radio :label="3">转赠规则</el-radio>-->
      <el-table-column label="所属规则" prop="type" align="left">
        <template #default="{row}">
          <div>
            <el-tag v-if="row.type==1">飞机规则</el-tag>
            <el-tag v-else-if="row.type==2" type="success">市场规则</el-tag>
            <el-tag v-else-if="row.type==3" type="success">转赠规则</el-tag>
            <div v-else>{{row.type || '--'}}</div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="right" fixed="right"  >
        <template #default="{row}">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(row)"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>


    <add ref="addRef" @success="getList"/>
  </div>
</template>

<script>
import {
  mRulList,
  mRulremove
} from "@/api/user/user"
import add from "./components/add.vue"
export default {
  name: "Role",
  components: {
    add
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [
      ],
      // 弹出层标题
      // 查询参数
      queryParams: {},
      imageUrl:"http://192.168.1.99:8802",
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询角色列表 */
    async getList() {
      this.loading = true
      let res = await mRulList()
      this.roleList = res.data.rulList
      this.loading = false
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.addRef.onOpen()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.addRef.onOpen(row.type)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.type
      this.$modal.confirm('确认删除此规则？').then(function () {
        return mRulremove({type:roleIds})
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {
      })
    },

    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },

    // 表单重置
    reset() {
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm")
      this.handleQuery()
    },

  }
}
</script>
